package com.hwl.statistics.task;

import com.hwl.statistics.service.DailyService;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class ScheduledTask {

    @Resource
    private DailyService dailyService;

    //每天凌晨1点执行统计数据的添加
    @Scheduled(cron = "0 0 1 * * ?")
    public void testGenStatisticsData() {
        String day = new DateTime().minusDays(1).toString("yyyy-MM-dd");
        log.info(dailyService.createStatisticsByDay(day) ? "统计数据生成成功！" : "统计数据生成失败！");
    }
}
